<?php

namespace App\Http\Controllers\Home;

use App\Models\User;
use Request;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
    /**
     * @return string
     */
    public function user()
    {
        return $users = new User();
    }

    /**
     * 用户请求前台主页视图
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
     */
    public function index()
    {
        if ($this->user()->login()['status'])                               /*密码和用户名正确才允许登录,并把id,user_name存入session*/
            return view('home/index');
        else                                                                /*密码或用户名错误重定向到登录视图*/
            return back();
    }

    /**
     * 用户请求登出视图
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function logout()
    {
        $this->user()->logout();
        return view('home/login');
    }

    /**
     *
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function do_signup()
    {
        if ($this->user()->signup()['status'])
            return redirect('home/login');
        return back();
    }

    /**
     * 用户注册视图
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function signup()
    {
        return view('home/signup');
    }
}
